package cn.summit.validation.annotation;


import cn.summit.validation.validor.TextLengthValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.Min;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 字符串长度检查
 *
 * @author summit
 * @since 2020/6/24 11:19
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(TextLength.List.class)
@Constraint(validatedBy = TextLengthValidator.class)
@Documented
public @interface TextLength {

    int min() default 0;

    int max() default Integer.MAX_VALUE;

    String message() default "{javax.validation.constraints.Length.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * Defines several {@link Min} annotations on the same element.
     *
     * @see Min
     */
    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {

        TextLength[] value();
    }
}
